import { InputQuestion, QuestionBase, SelectQuestion, TableBase, TextTable, TimeQuestion } from '@/components/public-template';
import { Api } from '@/config/api/archivesToReturn';
import { regExp } from '@/utils/regExp';
import dayjs from 'dayjs';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'fileName',
        label: '文件名称',
        placeholder: '请输入',
        reg: regExp.len100,
        prompt: '输入字符需小于100'
        // type: 'search',
        // state: {
        //   mode: '-',
        //   url: Api.toBeReturnList,
        //   protType: 'post',
        //   nameKey: 'fileName',
        //   nameValue: 'fileName'
        // }
      }),
      new InputQuestion({
        key: 'fileCode',
        label: '文件编码',
        placeholder: '请输入',
        reg: regExp.strLen20,
        prompt: '输入字符需小于20'
        // type: 'search',
        // state: {
        //   mode: '-',
        //   url: Api.toBeReturnList,
        //   protType: 'post',
        //   nameKey: 'fileCode',
        //   nameValue: 'fileCode'
        // }
      }),
      new InputQuestion({
        key: 'filesBoxCode',
        label: '档案编码',
        placeholder: '请输入',
        reg: regExp.strLen20,
        prompt: '输入字符需小于20'
        // type: 'search',
        // state: {
        //   mode: '-',
        //   url: Api.toBeReturnList,
        //   protType: 'post',
        //   nameKey: 'filesBoxCode',
        //   nameValue: 'filesBoxCode'
        // }
      }),
      new SelectQuestion({
        key: 'isOverdue',
        label: '是否逾期',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_BORROW_IS_RENEW'
        }
      }),
      new SelectQuestion({
        key: 'isRenew',
        label: '是否续借',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_BORROW_IS_RENEW'
        }
      }),
      new TimeQuestion({
        label: '申请时间',
        state: {
          showTime: true,
          keySplit: ['startTime', 'endTime'],
          format: 'YYYY-MM-DD HH:mm:ss',
          valueFormat: 'YYYY-MM-DD HH:mm:ss'
        }
      })
    ];
    return questions;
  }

  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'borrowCode',
        value: '借阅单据编号',
        type: 'slot',
        state: {
          slotName: 'borrowCode'
        }
      }),
      new TextTable({
        key: 'borrowType',
        value: '借阅类型',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_BORROW_BORROW_TYPE'
        }
      }),
      new TextTable({
        key: 'borrowCode',
        value: '借阅编码'
      }),
      new TextTable({
        key: 'fileName',
        value: '文件名称'
      }),
      new TextTable({
        key: 'fileCode',
        value: '文件编码'
      }),
      new TextTable({
        key: 'filesBoxCode',
        value: '档案编码'
      }),
      new TextTable({
        key: 'status',
        value: '状态'
      }),
      new TextTable({
        key: 'isOverdue',
        value: '是否逾期',
        type: 'custom',
        columns: {
          customRender: ({ text, record, index }) => {
            if (record.planReturnTime ?? '' !== '') {
              if (dayjs(record.planReturnTime).unix() > dayjs().unix()) {
                return '否';
              } else {
                return '是';
              }
            } else {
              return '';
            }
          }
        }
      }),
      new TextTable({
        key: 'isRenew',
        value: '是否续借',
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_BORROW_IS_RENEW'
        }
      }),
      new TextTable({
        key: 'borrowerName',
        value: '借阅人'
      }),
      new TextTable({
        key: 'borrowTime',
        value: '借阅时间'
      }),
      new TextTable({
        key: 'planReturnTime',
        value: '计划归还时间'
      })
    ];
    return tables;
  }

  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'local',
        value: '档案续借',
        type: 'primary',
        class: 'PlusOutlined'
      }),
      new TextTable({
        key: 'local',
        value: '档案归还',
        type: 'primary',
        class: 'PlusOutlined'
      })
    ];
    return icons;
  }
}

export default new HomeService();
